$(function() {

	// 点击ldap主要信息，继承对象和默认对象滑动效果
	$('body').on('click', ".addLdapLabelSlide", function() {
		slideLdapInfo(this);
	});

	// 点击ldap详细信息删除域名，对象和属性等
	$('body').on('click', ".deleteLdapLabelClick", function() {
		deleteLdapInfo(this);
	});
});

/**
 * 点击ldap详细信息新增域名，对象和属性等
 * @param type 域名、对象、属性
 * @param page 当前点击数据源或目标源区域对象
 * @returns 域名、对象、属性生成的HTML页面
 */
function addLdapDetail(type, page) {
	switch (type) {
	case 'addBase':
		var baseHtml = $('<div class="form-group">'
				+ '<label class="col-sm-2 control-label">域名<strong>*</strong></label>'
				+ '<div class="col-sm-9">'
				+ '<input class="form-control" name="baseContexs" type="text" value="" placeholder="如dc=com" />'
				+ '</div>'
				+ '<label class="fa fa-minus col-sm-1 form-control-static deleteLdapLabelClick"></label>'
				+ '</div>');
		$(page).parents(".addLdapObjectContent").append(baseHtml);
		break;
	case 'addUser':
		var userHtml = $('<div class="form-group">'
				+ '<label class="col-sm-2 control-label">对象<strong>*</strong></label>'
				+ '<div class="col-sm-9">'
				+ '<input class="form-control" name="baseContexs" type="text" value="" placeholder="如 inetOrgPerson" />'
				+ '</div>'
				+ '<label class="fa fa-minus col-sm-1 form-control-static deleteLdapLabelClick"></label>'
				+ '</div>');
		$(page).parents(".addLdapObjectContent").append(userHtml);
		break;
	case 'addProperty':
		var propertyHtml = $('<div class="form-group">'
				+ '<label class="col-sm-3 control-label">属性<strong>*</strong></label>'
				+ '<div class="col-sm-8">'
				+ '<input class="form-control" name="baseContexs" type="text" value="" placeholder="如 userId" />'
				+ '</div>'
				+ '<label class="fa fa-minus col-sm-1 form-control-static deleteLdapLabelClick"></label>'
				+ '</div>');
		$(page).parents(".addLdapObjectContent").append(propertyHtml);
		break;
	default:
		break;
	}
}

/**
 * 点击ldap详细信息删除域名，对象和属性等
 * @param obj 域名、对象、属性对象
 * @returns
 */
function deleteLdapInfo(obj) {
	$(obj).parents('.form-group').remove();
}

/**
 * 点击标题滑动效果
 * @param type 主要信息，继承对象和默认对象
 * @returns
 */
function slideLdapInfo(type) {
	var $slideType = $(type).find("i");
	var $slideUp = $slideType.hasClass('fa-caret-right');
	var $slideDown = $slideType.hasClass('fa-caret-down');
	var $slideObject = $(type).parents('.addLdapObjectTitle').next();
	if ($slideDown) {
		$slideObject.slideUp();
		$slideType.attr('class', "fa fa-caret-right fa-x");
	} else if ($slideUp) {
		$slideObject.slideDown();
		$slideType.attr('class', "fa fa-caret-down fa-x");
	}
}